const mongoose = require('mongoose');
const dotenv = require('dotenv');
const Job = require('../models/jobModel');

// Load environment variables
dotenv.config({ path: '../../.env' });

// Connect to database
mongoose.connect(process.env.MONGODB_URI || 'mongodb://localhost:27017/job-recommendation')
  .then(() => console.log('DB connection successful!'));

// Sample job data
const jobs = [
  {
    title: 'Frontend Developer',
    company: 'TechCorp',
    location: {
      type: 'Point',
      coordinates: [-73.9857, 40.7484], // NYC
      address: '350 Fifth Avenue',
      city: 'New York',
      state: 'NY',
      country: 'USA',
      zipCode: '10118'
    },
    description: 'We are looking for an experienced frontend developer to join our team.',
    requirements: [
      'Proficient in HTML, CSS, and JavaScript',
      'Experience with React.js',
      'Knowledge of responsive design principles'
    ],
    salary: {
      min: 80000,
      max: 120000,
      currency: 'USD'
    },
    jobType: 'Full-time',
    experienceLevel: 'Mid-level',
    postedDate: new Date('2023-07-01'),
    deadline: new Date('2023-08-01'),
    isActive: true,
    tags: ['React', 'JavaScript', 'CSS', 'Frontend'],
    applicationUrl: 'https://techcorp.com/careers/frontend-developer',
    companyLogo: 'https://example.com/logos/techcorp.png'
  },
  {
    title: 'Backend Developer',
    company: 'DataSystems',
    location: {
      type: 'Point',
      coordinates: [-122.4194, 37.7749], // San Francisco
      address: '123 Market Street',
      city: 'San Francisco',
      state: 'CA',
      country: 'USA',
      zipCode: '94103'
    },
    description: 'Join our backend team to build scalable and efficient server-side applications.',
    requirements: [
      'Strong knowledge of Node.js and Express',
      'Experience with MongoDB or other NoSQL databases',
      'Familiarity with RESTful API design'
    ],
    salary: {
      min: 90000,
      max: 140000,
      currency: 'USD'
    },
    jobType: 'Full-time',
    experienceLevel: 'Senior',
    postedDate: new Date('2023-07-05'),
    deadline: new Date('2023-08-05'),
    isActive: true,
    tags: ['Node.js', 'MongoDB', 'Express', 'Backend'],
    applicationUrl: 'https://datasystems.com/careers/backend-developer',
    companyLogo: 'https://example.com/logos/datasystems.png'
  },
  {
    title: 'Full Stack Developer',
    company: 'WebSolutions',
    location: {
      type: 'Point',
      coordinates: [-118.2437, 34.0522], // Los Angeles
      address: '456 Hollywood Blvd',
      city: 'Los Angeles',
      state: 'CA',
      country: 'USA',
      zipCode: '90028'
    },
    description: 'Looking for a full stack developer to work on our web applications from frontend to backend.',
    requirements: [
      'Experience with JavaScript, HTML, CSS',
      'Knowledge of both frontend (React) and backend (Node.js) technologies',
      'Database experience with MongoDB or PostgreSQL'
    ],
    salary: {
      min: 100000,
      max: 150000,
      currency: 'USD'
    },
    jobType: 'Full-time',
    experienceLevel: 'Mid-level',
    postedDate: new Date('2023-07-10'),
    deadline: new Date('2023-08-10'),
    isActive: true,
    tags: ['React', 'Node.js', 'MongoDB', 'Full Stack'],
    applicationUrl: 'https://websolutions.com/careers/full-stack-developer',
    companyLogo: 'https://example.com/logos/websolutions.png'
  },
  {
    title: 'UX/UI Designer',
    company: 'DesignHub',
    location: {
      type: 'Point',
      coordinates: [-87.6298, 41.8781], // Chicago
      address: '789 Michigan Ave',
      city: 'Chicago',
      state: 'IL',
      country: 'USA',
      zipCode: '60611'
    },
    description: 'We are seeking a talented UX/UI Designer to create amazing user experiences.',
    requirements: [
      'Proficiency in design tools like Figma, Sketch, Adobe XD',
      'Portfolio demonstrating UI/UX projects',
      'Understanding of user-centered design principles'
    ],
    salary: {
      min: 75000,
      max: 110000,
      currency: 'USD'
    },
    jobType: 'Full-time',
    experienceLevel: 'Mid-level',
    postedDate: new Date('2023-07-15'),
    deadline: new Date('2023-08-15'),
    isActive: true,
    tags: ['UX', 'UI', 'Design', 'Figma'],
    applicationUrl: 'https://designhub.com/careers/ux-ui-designer',
    companyLogo: 'https://example.com/logos/designhub.png'
  },
  {
    title: 'Data Scientist',
    company: 'AnalyticsPro',
    location: {
      type: 'Point',
      coordinates: [-122.3321, 47.6062], // Seattle
      address: '101 Pike Street',
      city: 'Seattle',
      state: 'WA',
      country: 'USA',
      zipCode: '98101'
    },
    description: 'Join our data science team to solve complex problems using data analysis and machine learning.',
    requirements: [
      'Strong background in statistics and mathematics',
      'Experience with Python and data science libraries',
      'Knowledge of machine learning algorithms'
    ],
    salary: {
      min: 110000,
      max: 160000,
      currency: 'USD'
    },
    jobType: 'Full-time',
    experienceLevel: 'Senior',
    postedDate: new Date('2023-07-20'),
    deadline: new Date('2023-08-20'),
    isActive: true,
    tags: ['Python', 'Machine Learning', 'Data Science', 'AI'],
    applicationUrl: 'https://analyticspro.com/careers/data-scientist',
    companyLogo: 'https://example.com/logos/analyticspro.png'
  }
];

// Import data into database
const importData = async () => {
  try {
    await Job.deleteMany(); // Clear existing data
    await Job.create(jobs);
    console.log('Data successfully loaded!');
    process.exit();
  } catch (err) {
    console.error(err);
    process.exit(1);
  }
};

// Delete all data from database
const deleteData = async () => {
  try {
    await Job.deleteMany();
    console.log('Data successfully deleted!');
    process.exit();
  } catch (err) {
    console.error(err);
    process.exit(1);
  }
};

// Run script with argument: node seedData.js --import or --delete
if (process.argv[2] === '--import') {
  importData();
} else if (process.argv[2] === '--delete') {
  deleteData();
} else {
  console.log('Please use --import or --delete as an argument');
  process.exit();
} 